# -*- coding: utf-8 -*-
"""
获取智能体中心可用的分类列表
"""

import os
import sys
from pathlib import Path
from dotenv import load_dotenv

# 添加项目根目录到路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))

# 加载环境变量
load_dotenv(project_root / '.env')

from src.llm.hiagent_app.utils.api_client import HiAgentAPIClient


def main():
    """获取分类列表"""
    client = HiAgentAPIClient()

    print("正在获取智能体中心分类列表...")

    result = client.make_request(
        action="ListAppCenterCategory",
        body={"Top": {}}
    )

    print(f"\n原始返回结果:\n{result}\n")

    # 处理不同的响应格式
    if "Response" in result:
        if result.get("Response", {}).get("Error"):
            error = result["Response"]["Error"]
            print(f"获取失败: {error.get('Code')} - {error.get('Message')}")
            return
        categories = result["Response"].get("Categories", [])
    else:
        # 直接返回格式
        categories = result.get("Categories", [])

    print(f"\n找到 {len(categories)} 个分类:\n")
    print("=" * 60)

    for cat in categories:
        code = cat.get("CategoryCode", "")
        name = cat.get("CategoryName", "")
        print(f"代码: {code:20s} | 名称: {name}")

    print("=" * 60)
    print(f"\n建议使用第一个分类代码: {categories[0].get('CategoryCode')}")


if __name__ == "__main__":
    main()
